<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/mylayer.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/kindeditor/kindeditor.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<!-- 为 ECharts 准备一个定义了宽高的 DOM -->
<div >
    <div class="layui-input-inline">
        <div id="main1" style="width: 600px;height:400px;"></div>
    </div>
    <div class="layui-input-inline">
        <div id="main2" style="width: 600px;height:400px;"></div>
    </div>
    <div class="layui-input-inline">
        <div id="main3" style="width: 600px;height:400px;"></div>
    </div>
</div>

<script src="/static/echarts.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart1 = echarts.init(document.getElementById('main1'));
    var myChart2 = echarts.init(document.getElementById('main2'));
    var myChart3 = echarts.init(document.getElementById('main3'));

    $.post(
        '/echarts?method=display1',
        function(jsonObj) {
            //[{name: 'Java1807', value: 3},{name: 'Java1812', value: 1}]
            console.log(jsonObj);
            var xArray = new Array();
            var yArray = new Array();
            for (var buildingCount of jsonObj) {
                xArray.push(buildingCount.buildingId+'号楼');
                yArray.push(buildingCount.amount);
            }
            var pieData = jsonObj.map(function(item) {
                return {name: item.buildingId, value: item.amount};
            });
            // 指定图表的配置项和数据
            var option1 = {
                title: {
                    text: '宿舍楼-人数'
                },
                tooltip: {},
                legend: {
                    data: ['人数']
                },
                xAxis: {
                    data:xArray
                },
                yAxis: {},
                series: [
                    {
                        name: '人数',
                        type: 'bar',
                        showBackground: true,
                        backgroundStyle: {
                            color: 'rgba(220, 220, 220, 0.8)'
                        },
                        data:yArray
                    }
                ]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart1.setOption(option1);


            //-----------饼状图----------------
            var option2 = {
                title: {
                    text: '每个宿舍楼人数分布',
                    subtext: '占比',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: '人数',
                        type: 'pie',
                        radius: '50%',
                        data: pieData,
                        roseType: 'angle',
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };

            myChart2.setOption(option2);
        },
        'json'
    );





</script>
</body>
</html>